package com.huat.spring_boot;


import com.huat.spring_boot.pojo.StudentGrade;
import com.huat.spring_boot.service.StudentGradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
//@RequestMapping("/api/student-grades")
public class StudentGradeController {

    @Autowired
    private StudentGradeService studentGradeService;

    @GetMapping("/student/{id}")
    public StudentGrade getStudentGradeById(@PathVariable Long id) {
        return studentGradeService.findById(id);
    }

    @GetMapping("/student")
    public List<StudentGrade> getAllStudentGrades() {
        return studentGradeService.findAll();
    }

    @PostMapping("/student")
    public void addStudentGrade(@RequestBody StudentGrade studentGrade) {
        studentGradeService.save(studentGrade);
    }

    @PutMapping("/student/{id}")
    public void updateStudentGrade(@PathVariable Long id, @RequestBody StudentGrade studentGrade) {
        studentGrade.setId(id);
        studentGradeService.save(studentGrade);
    }

    @DeleteMapping("/student/{id}")
    public void deleteStudentGrade(@PathVariable Long id) {
        studentGradeService.delete(id);
    }
}
